package service

import (
	"encoding/json"
	"net/http"

	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
)

const baseUrl_zj = "http://10.93.0.88:8086/wjzwfw/rest/"

func GetPositionAndDate(c *gin.Context) {
	url := baseUrl_zj + "wjbigscreen/getpositionanddate"
	var params AllInOnePC
	if err := c.ShouldBindJSON(&params); err == nil {
		jsonData, errJson := json.Marshal((params))
		if errJson != nil {
			logrus.Error(errJson)
		}
		data := []byte(jsonData)
		Response, err1 := Post[ResponsePack[PositionAndDateResponse]](url, data, c)
		if err1 != nil {
			c.JSON(http.StatusOK, ErrorResponse(0, err1))
			return
		}
		c.JSON(http.StatusOK, SuccessResponse(Response.Custom.Array))
	} else {
		c.JSON(http.StatusOK, ErrorResponse(0, err))
	}
}

func GetYtjcount(c *gin.Context) {
	url := baseUrl_zj + "wjbigscreen/getYtjcount"
	var params RequestParams[YtjCountParamsItem]
	if err := c.ShouldBindJSON(&params); err == nil {
		jsonData, errJson := json.Marshal((params))
		if errJson != nil {
			logrus.Error(errJson)
		}
		data := []byte(jsonData)
		Response, err1 := Post[ResponsePack[YtjCountResponse]](url, data, c)
		if err1 != nil {
			c.JSON(http.StatusOK, ErrorResponse(0, err1))
			return
		}
		c.JSON(http.StatusOK, SuccessResponse(Response.Custom.Ytjlist))
	} else {
		c.JSON(http.StatusOK, ErrorResponse(0, err))
	}
}

func GetYtjcountTown(c *gin.Context) {
	url := baseUrl_zj + "wjbigscreen/getYtjcountTown"
	var params RequestParams[YtjCountParamsItem]
	if err := c.ShouldBindJSON(&params); err == nil {
		jsonData, errJson := json.Marshal((params))
		if errJson != nil {
			logrus.Error(errJson)
		}
		data := []byte(jsonData)
		Response, err1 := Post[ResponsePack[YtjArrayResponse]](url, data, c)
		if err1 != nil {
			c.JSON(http.StatusOK, ErrorResponse(0, err1))
			return
		}
		c.JSON(http.StatusOK, SuccessResponse(Response.Custom.Ytjarray))
	} else {
		c.JSON(http.StatusOK, ErrorResponse(0, err))
	}
}
